﻿
Imports System.Data
Imports VSModel
Imports Cls_Common
Imports SecurityService
Partial Class Control_HinhDo_Detail
    Inherits System.Web.UI.UserControl
    Private Shared ReadOnly log As log4net.ILog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
#Region "Sub and Function "
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            getLoai()
            getNgonngu()
            If Not Request.QueryString("Hinhdoid").ToString.Equals("0") Then
                hidID.Value = Request.QueryString("Hinhdoid")
                ShowData()
            End If
        End If
    End Sub
    Protected Sub getNgonngu()
        ddlNgonngu.Items.Clear()
        ddlNgonngu.AppendDataBoundItems = True
        ddlNgonngu.Items.Add(New ListItem("---Chọn---", ""))
        Using data As New VSEntities
            Dim p = (From q In data.Languages Select q.LanguageId, q.Name).ToList
            ddlNgonngu.DataValueField = "LanguageId"
            ddlNgonngu.DataTextField = "Name"
            ddlNgonngu.DataSource = p
            ddlNgonngu.DataBind()
            ddlNgonngu.SelectedValue = 0
        End Using
    End Sub
    Protected Sub getLoai()
        ddlLoai.Items.Clear()
        ddlLoai.AppendDataBoundItems = True
        ddlLoai.Items.Add(New ListItem("---Chọn---", ""))
        Using data As New VSEntities
            Dim p = (From q In data.HinhDoTypes Select q.TypeId, q.Name).ToList
            ddlLoai.DataValueField = "TypeId"
            ddlLoai.DataTextField = "Name"
            ddlLoai.DataSource = p
            ddlLoai.DataBind()
            ddlLoai.SelectedValue = 0
        End Using
    End Sub
    Protected Sub ShowData()
        Using data As New VSEntities
            Dim p As HinhDo = (From q In data.HinhDoes Where q.HinhDoId = hidID.Value Select q).SingleOrDefault
            If Not p Is Nothing Then
                txtHinhdocode.Text = IIf(IsNothing(p.HinhDoCode) = True, "", p.HinhDoCode)
                txtTengoi.Text = IIf(IsNothing(p.TenGoi) = True, "", p.TenGoi)
                txtDactinh.Text = IIf(IsNothing(p.DacTinh) = True, "", p.DacTinh)
                ddlLoai.SelectedValue = IIf(IsNothing(p.LoaiId) = True, "0", p.LoaiId)
                ddlNgonngu.SelectedValue = IIf(IsNothing(p.NgonNguId) = True, "", p.NgonNguId)
                hidImagePath.Text = IIf(IsNothing(p.FileURL) = True, "", p.FileURL)
                imgUpload.ImageUrl = IIf(IsNothing(p.FileURL) = True, "", p.FileURL)
                imgUploadNone.ImageUrl = IIf(IsNothing(p.FileURLNone) = True, "", p.FileURLNone)
            End If
        End Using
    End Sub
#End Region

End Class
